import {defineStore} from 'pinia'
import { computed, ref } from 'vue'

// 规范 use 开头的驼峰命名  defineStore(仓库名字, 回调函数)  这个回调函数当成setup使用即可
export const useCounterStore = defineStore('counter',() => {
    // state
    const count= ref(10)
    // getter
    const doubleCount = computed(() => count.value * 2)
    // mutations
    const changeCount = () => {
        count.value++
    }
    // actions
    const changeCountAsync = () => {
        setTimeout(() => {
            count.value = count.value +10
        }, 3000)
    }
    return {
        count,
        doubleCount,
        changeCount,
        changeCountAsync
    }
})